from common.connect_db import MyDB

my_db = MyDB()


class DataBaseOnShop:

    @staticmethod
    def get_member_id(shop_id):
        """
        根据店铺id获取会员id
        :param member_id:
        :return:
        """
        sql = "select member_id from life_online_shop_shops " \
              " ""where id='%s' limit 1" % shop_id
        member_id = my_db.execute_select('onshop', sql)
        if member_id[0]:
            return member_id[0][0]
        else:
            print("数据出错了，请检查是否存在该店铺")

    @staticmethod
    def filter_life_online_shop_shops_by_id(store_id):
        """
        通过商家ID获得详细信息
        :param store_id:
        :return:
        """
        sql = "select * from life_online_shop_shops where id= '%s'" % store_id
        result = my_db.execute_select('onshop', sql)
        if len(result) == 1:
            return result[0]
        else:
            raise ValueError('查询不到商家信息！')

    @staticmethod
    def filter_life_online_shop_shops_by_member_id(member_id):
        """
        通过member_id获得详细信息
        :param member_id:
        :return:
        """
        sql = "select * from life_online_shop_shops where member_id= '%s'" % member_id
        result = my_db.execute_select('onshop', sql)
        if len(result) == 1:
            return result[0]
        else:
            raise ValueError('查询不到商家信息！')

    @staticmethod
    def filter_life_online_shop_shops_by_shop_name(shop_name):
        """
        通过店铺名称获得详细信息
        :param shop_name:
        :return:
        """
        sql = "select * from life_online_shop_shops where shop_name= '%s'" % shop_name
        result = my_db.execute_select('onshop', sql)
        if len(result) == 1:
            return result[0]
        else:
            raise ValueError('查询不到商家信息！')
